// test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <string>
#include "quiz_inc.h"
using namespace std;


int main(int argc, char* argv[])
{
	int res, code;
	std::string question, answer;
	char user_answer[128];

	// Create quiz object
	IQuiz *quiz = CreateQuiz();

	if (quiz != NULL)
	{
		// Read data
		QuizParams params;
		memset(&params, 0, sizeof(params));
		params.dictFile = "..\\questions.txt";
		params.userFile = "..\\users.txt";

		res = quiz->Init(params);

		if (res == QUIZ_OK)
		{
			do
			{
				system("cls");
				printf("1. Next question\n");
				printf("2. Exit\n");

				code = getchar();
				getchar(); // for Enter after number
				if (code == '1')
				{
					question = quiz->GetQuestion();

					printf("%s\n", question.c_str());
					printf("answer: ");
					scanf("%s", &user_answer);
					getchar(); // for Enter after number

					//if (!strcmp(quiz->GetAnswer().c_str(), user_answer))
					{
						printf("OK! +2 points\n");
						if (quiz->GivePoints("pinkerton", 2) != QUIZ_OK)
						{
							printf("Error - exit\n");
							break;
						}
					}
					//else
					//	printf("FAIL\n");

					if (quiz->WriteUserInfo() != QUIZ_OK)
					{
						printf("Error - exit\n");
						break;
					}

					printf("Press any key\n");
					getchar();
				}
				else if (code == '2')
					break;
			}while (code != 13);

		}
	}

	return 0;
}

